#include "EnemyOwnedState.h"
#include "State.h"
#include "Enemy.h"
#include "GlobalDefines.h"
#include "MessageHandler.h"
#include "DXConsole.h"


// Idle State
IdleState* IdleState::Instance()
{
	static IdleState instance;	

	return &instance;
}

void IdleState::Enter(Enemy *m_enemy)
{
	m_enemy->setVectorRotation(270,0,0);	
}

void IdleState::Execute(Enemy *m_enemy)
{
	m_enemy->SetTrigState(1);
	if(m_enemy->GetTrigState() == 1)
	{
		m_enemy->getFSM()->ChangeState(PtrlState::Instance());
	}
}

void IdleState::Exit(Enemy *m_enemy)
{

}

// Patrol state
PtrlState* PtrlState::Instance()
{
  static PtrlState instance;

  return &instance;
}

void PtrlState::Enter(Enemy *m_enemy)
{

}

void PtrlState::Execute(Enemy *m_enemy)
{  
	m_enemy->enemyAI();

	if(m_enemy->GetTrigState() == 2)
	{
		m_enemy->getFSM()->ChangeState(AtkState::Instance());
	}
}

void PtrlState::Exit(Enemy *m_enemy)
{
	m_enemy->playAwrSound();
}

// Attack state
AtkState* AtkState::Instance()
{
	static AtkState instance;

	return &instance;
}

void AtkState::Enter(Enemy *m_enemy)
{

}

void AtkState::Execute(Enemy *m_enemy)
{
	m_enemy->ChasePlayer();

	m_enemy->combat();

	if(m_enemy->GetTrigState() == 4)
	{
		m_enemy->getFSM()->ChangeState(DthState::Instance());
	}
}

void AtkState::Exit(Enemy *m_enemy)
{	
	m_enemy->playDthSound();
}

// Death State
DthState* DthState::Instance()
{
	static DthState instance;

	return &instance;
}

void DthState::Enter(Enemy *m_enemy)
{
	
}

void DthState::Execute(Enemy *m_enemy)
{
	m_enemy->setVectorRotation(180.0f,0.0f,0.0f);

	if(diMgr.isKeyDown(DIK_5))
	{
		m_enemy->getFSM()->ChangeState(IdleState::Instance());
	}
}

void DthState::Exit(Enemy *m_enemy)
{
	
}

// Flee State
FleeState* FleeState::Instance()
{
	static FleeState instance;

	return &instance;
}

void FleeState::Enter(Enemy *m_enemy)
{

}

void FleeState::Execute(Enemy *m_enemy)
{
	m_z += 5;
	m_enemy->setPosition(m_x, m_y, m_z);

	if(diMgr.isKeyDown(DIK_5))
	{
		m_enemy->getFSM()->ChangeState(IdleState::Instance());
	}
}

void FleeState::Exit(Enemy *m_enemy)
{
	
}

